//
//  VideoPlayerViewController.m
//  HuateVideo
//
//  Created by Tiger on 12-5-17.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "VideoPlayerViewController.h"

@interface VideoPlayerViewController ()

@end
//@implementation MPMoviePlayerController(d)
//
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
//{
//    self.view.frame= CGRectMake(0, 0, 480, 320);
//    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight);
//}
//@end

@implementation VideoPlayerViewController
@synthesize moviePlayer;
-(void)dealloc{
    [moviePlayer release];
    [super dealloc];
}

//- (id)initWithVideo:(Video *)_video
//{
//    self = [super init];
//    if (self) {
//        // Custom initialization
//        video = [_video retain];
//    }
//    return self;
//}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
	// Do any additional setup after loading the view.
    NSString* moviePath=[[NSBundle mainBundle] pathForResource:@"ad" ofType:@"mp4"];        
    moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
    
    //    [self.view setFrame:CGRectMake(0, 0, 480, 320)];
    [moviePlayer.view setFrame:CGRectMake(0, 0, 480, 320)];
    //    [moviePlayer.view setBounds:CGRectMake(0, 0, 480, 320)];
    
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(Moviefinished:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];
    moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    
    moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
    //    [self.view addSubview:moviePlayer.view ];
    self.view=moviePlayer.view;
    [moviePlayer play];  
}

-(void)Moviefinished:(NSNotification*)notify{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    
    MPMoviePlayerController* player=(MPMoviePlayerController*)[notify object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player
     ];
    [self dismissModalViewControllerAnimated:YES];    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //    [moviePlayer.view setFrame:CGRectMake(0, 0, 480, 320)];
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    
}

@end
